
import type { ICapability } from "@/components/capability";
import * as apis from "@shared/apis";
import { asyncConfirm } from "@/utils/funs";
import { message } from "@/components/base";

interface IData {
    refresh?: () => Promise<void>;
    record?: apis.users.IUser;
}

/** 删除用户 */
export const deleteUser: ICapability = {
    title: '删除',
    start: async (data: IData) => {
        await asyncConfirm({
            title: '删除用户',
            content: `是否确认删除用户 ${data?.record?.username} ?`,
            okText: '删除',
            okType: 'danger',
        })
        await onSubmit(data);
    }
}

const onSubmit = async (data: IData) => {
    await data?.refresh?.();
    if (!data?.record) return;
    await apis.users.delete.post(data.record.id);
    message.success('删除成功');
    await data?.refresh?.();
}

